package com.huika.dealontop.control.shops.holder;

import android.content.Context;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.huika.dealontop.R;
import com.huika.dealontop.control.base.extend.BaseViewHolder;
import com.huika.dealontop.support.domain.ProductDetailsBean;
import com.huika.dealontop.utils.DateTimeTool;
import com.huika.dealontop.utils.UIUtils;
import com.huika.huikalib.utils.StringUtils;

/**
 * Author: Victor Wu <br/>
 * Email: victor-wu*foxmail.com <br/>
 * Time: 2015/11/27 11:29 <br/>
 * Description: TODO
 */
public class ProductNoticeHolder extends BaseViewHolder<ProductDetailsBean.ProductBean> {
    private View view;

    private View ll_productRuleName;
    private View ll_productOther;

    public ProductNoticeHolder(Context context) {
        super(context);
    }

    @Override
    protected View initView() {
        view = View.inflate(UIUtils.getContext(), R.layout.fragment_product_notice, null);
        return view;
    }

    @Override
    protected void assignView(View rootView) {
        ll_productRuleName = findViewById(R.id.ll_productRuleName);
        ll_productOther = findViewById(R.id.ll_productOther);
    }

    @Override
    protected void refreshView(ProductDetailsBean.ProductBean data) {
        if(data == null){
            return;
        }
        showServicesKeywords();
        //有效期
        ((TextView)view.findViewById(R.id.tv_product_detail_validity)).setText(
                UIUtils.getFormatString(R.string.product_validity_show,
                        DateTimeTool.dmyDate(data.getStartDate()),
                        DateTimeTool.dmyDate(data.getEndDate()))
        );
        //使用时间
        ((TextView) view.findViewById(R.id.tv_product_detail_useTime)).setText(data.getUsePeriod());
        //预约提醒
        ((TextView) view.findViewById(R.id.tv_product_detail_reservation)).setText(data.getBespeakRemind());
        //使用规则
        ((TextView) view.findViewById(R.id.tv_product_detail_productRuleName)).setText(data.getUseLimit());
        ll_productRuleName.setVisibility(StringUtils.isEmpty(data.getUseLimit()) ? View.GONE : View.VISIBLE );
        //补充说明
        ((TextView) view.findViewById(R.id.tv_product_detail_other_help)).setText(data.getOther());
        ll_productOther.setVisibility(StringUtils.isEmpty(data.getOther()) ? View.GONE : View.VISIBLE );
    }

    private void showServicesKeywords() {
        ProductDetailsBean.ProductBean.MerchantServicesBean merchantServices = mData.getMerchantServices();
        if (merchantServices == null) {
            return;
        }
        view.findViewById(R.id.free_wifi_tag).setVisibility(merchantServices.isIsFreeWifi() ? View.VISIBLE : View.GONE);
        view.findViewById(R.id.free_drinks_tag).setVisibility(merchantServices.isIsFreeDrinks() ? View.VISIBLE : View.GONE);
        view.findViewById(R.id.free_parking_tag).setVisibility(merchantServices.isIsFreeParking() ? View.VISIBLE : View.GONE);
        view.findViewById(R.id.gift_tag).setVisibility(merchantServices.isIsGift() ? View.VISIBLE : View.GONE);
        view.findViewById(R.id.dessert_tag).setVisibility(merchantServices.isIsDessert() ? View.VISIBLE : View.GONE);
        view.findViewById(R.id.door_service_tag).setVisibility(merchantServices.isIsDoorService() ? View.VISIBLE : View.GONE);
    }
}
